package thread;

import java.util.Random;
import java.util.concurrent.CountDownLatch;

public class testDemo32 {
    public static void main(String[] args) throws InterruptedException {
        CountDownLatch count=new CountDownLatch(10);
        for (int i = 0; i <10 ; i++) {
            int num=i;
            Thread t=new Thread(()->{
                System.out.println("线程"+Thread.currentThread().getName()+"开始下载"+num+"任务");
                Random r=new Random();
                int time=r.nextInt(5)*1000;
                try {
                    Thread.sleep(time);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                System.out.println("任务"+num+"执行完成");
                count.countDown();
            });
            t.start();
            
        }
       count.await();
        System.out.println("所有任务执行完毕");
    }
}
